package com.sjy.project.fym.api;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.sjy.common.constant.UserContext;
import com.sjy.common.entity.SecuryUserDetail;
import com.sjy.common.result.BaseResponse;
import com.sjy.common.utils.AesEncrypt;
import com.sjy.common.utils.DateUtils;
import com.sjy.common.utils.GPSUtil;
import com.sjy.common.utils.ListUtils;
import com.sjy.common.utils.MapUtils;
import com.sjy.common.utils.StringUtils;
import com.sjy.common.utils.TokenUtil;
import com.sjy.common.utils.WeChatUtils;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.framework.web.page.TableDataInfo;
import com.sjy.project.fym.accessToken.domain.FyAccessToken;
import com.sjy.project.fym.accessToken.service.IFyAccessTokenService;
import com.sjy.project.fym.apply.domain.FyGoods;
import com.sjy.project.fym.apply.domain.FyGoodsApply;
import com.sjy.project.fym.apply.domain.FyGoodsApplyHis;
import com.sjy.project.fym.apply.service.IFyGoodsApplyHisService;
import com.sjy.project.fym.apply.service.IFyGoodsApplyService;
import com.sjy.project.fym.apply.service.IFyGoodsService;
import com.sjy.project.fym.lab.domain.FyLab;
import com.sjy.project.fym.lab.service.IFyLabService;
import com.sjy.project.fym.place.domain.FyPlace;
import com.sjy.project.fym.place.service.IFyPlaceService;
import com.sjy.project.fym.signin.domain.FyUserSignin;
import com.sjy.project.fym.signin.domain.FyUserSigninVo;
import com.sjy.project.fym.signin.service.IFyUserSigninService;
import com.sjy.project.fym.team.domain.FyTeam;
import com.sjy.project.fym.team.service.IFyTeamService;
import com.sjy.project.fym.user.domain.FyUser;
import com.sjy.project.fym.user.service.IFyUserService;
import com.sjy.project.system.user.domain.User;
import com.sjy.project.system.user.service.IUserService;

import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api(value = "设计院大屏接口相关", description = "设计院对接相关接口", tags = {"设计院大屏接口"})
@RequestMapping({"/api/fym/sjy"})
public class ApiSjyDPController extends BaseController {
  @Autowired
  private IUserService userService;
  @Autowired
  private IFyPlaceService fyPlaceService;
  @Autowired
  private IFyLabService fyLabService;
  @Autowired
  private IFyTeamService fyTeamService;
  @Autowired
  private IFyAccessTokenService fyAccessTokenService;
  @Autowired
  private IFyGoodsApplyService applyService;
  @Autowired
  private IFyGoodsService goodsService;
  @Autowired
  private IFyGoodsApplyHisService hisService;
  @Autowired
  private IFyUserService fyUserService;
  @Autowired
  private IFyUserSigninService fyUserSigninService;
  @Autowired
  private JdbcTemplate jdbcTemplate;
  
  @Autowired
  private TokenUtil tokenUtil;

	@ApiOperation(value = "100.核酸检测点情况统计", position = 100,notes = "核酸检测点点数量、队伍数量、物资上报需求数量、打卡人数(总人数、公安、卫健、社区)")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
	})
	@RequestMapping(value = "/allDataSta",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> allDataSta() {
		try {
			String sql = "select * from v_all_data_sta";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			return BaseResponse.generateOKResponseEntity(ListUtils.mapListSetKeyUncamelCase(list));
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
	@ApiOperation(value = "101.核酸检测点各个状态数量统计 已启用、未启用、未定位", position = 101,notes = "未定位就是没有lngSjy 或者 latSjy")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
	})
	@RequestMapping(value = "/placeStatusSta",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> placeStatusSta() {
		try {
			String sql = "select * from v_place_status_sta";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			return BaseResponse.generateOKResponseEntity(ListUtils.mapListSetKeyUncamelCase(list));
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
	
	@ApiOperation(value = "102.采样点清单，用来地图打点", position = 102,notes = "")
	@ApiImplicitParams({
  	  @ApiImplicitParam(name = "placeId", value = "核酸采样点编号", required = false, example = "200"),
  	  @ApiImplicitParam(name = "placeName", value = "核酸采样点名称", required = false, example = "海城"),
  	  @ApiImplicitParam(name = "zone", value = "行政区划", required = false, example = "温州"),
  	  @ApiImplicitParam(name = "community", value = "社区", required = false, example = "xx"),
  	  @ApiImplicitParam(name = "addr", value = "采样点具体位置", required = false, example = "xx"),
  	  @ApiImplicitParam(name = "mgrName", value = "指挥长", required = false, example = "林"),
  	  @ApiImplicitParam(name = "mgrPhone", value = "手机号", required = false, example = "158"),
  	  @ApiImplicitParam(name = "status", value = "状态 1=正常,2=备用", required = false, example = "1"),
  	  @ApiImplicitParam(name = "pageNum", value = "当前页", required = false, example = "1"),
  	  @ApiImplicitParam(name = "pageSize", value = "分页大小", required = false, example = "15"),
  	  @ApiImplicitParam(name = "orderByColumn", value = "排序字段", required = false, example = "create_time"),
  	  @ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc", required = false, example = "desc"),
  	 
    })
    @PostMapping({"/placeList"})
    public ResponseEntity<BaseResponse<TableDataInfo<FyPlace>>> placeList(@ApiIgnore FyPlace fyPlace)
    {
        startPage();
        List<FyPlace> list = fyPlaceService.selectFyPlaceList(fyPlace);
        return BaseResponse.generateOKResponseEntity(getDataTable(list));
    }
	@ApiOperation(value = "103、根据placeId获取场所信息详情 包含队伍人员", position = 103, notes = "")
    @ApiImplicitParams({
  	  @ApiImplicitParam(name = "placeId", value = "场所编号", required = false, example = "1")
    })
    @PostMapping({"/getPlaceByPlaceId"})
    public ResponseEntity<BaseResponse<FyPlace>> getPlaceByPlaceId(Long placeId) throws Exception
    { 
    	FyPlace place = fyPlaceService.selectFyPlaceByPlaceId(placeId);
    	if(place != null) {
    		return BaseResponse.generateOKResponseEntity(place);
    	}
    	return BaseResponse.generateBadResponseEntity(500,"获取场所信息失败", place);
    	
    }
    @Log(title = "防疫点信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editPlace")
    @ApiOperation(value = "104、修改防疫点信息", position = 104, notes = "")
    @ApiImplicitParams({
  	  @ApiImplicitParam(name = "placeId", value = "核酸采样点ID", required = true, example = "海城"),
	  @ApiImplicitParam(name = "status", value = "状态 1=正常,2=备用", required = false, example = "1"),
	  @ApiImplicitParam(name = "lngSjy", value = "经度2000 格式", required = false, example = "1"),
	  @ApiImplicitParam(name = "latSjy", value = "纬度 2000格式", required = false, example = "1"),
	  @ApiImplicitParam(name = "signInRadius", value = "签到打卡半径 单位 米", required = false, example = "1"),
	  @ApiImplicitParam(name = "cameraCode", value = "摄像头编号，多个用,分割", required = false, example = "1,2,3"),
		 
	 })
    public ResponseEntity<BaseResponse> editPlace(@ApiIgnore FyPlace fyPlace)
    {
    	if(fyPlace.getPlaceId()==null) {
        	return BaseResponse.generateBadResponseEntity("修改的时候placeId不能为空", null);
    	}
    	SecuryUserDetail user = UserContext.getUserSession();
    	fyPlace.setUpdateBy(user.getLoginName());
    	
    	//更新lngSjy latSjy 到 lng lat
//        double[] lnglat = GPSUtil.bd09_To_gps84(new Double(fyPlace.getLatSjy()+""), new Double(fyPlace.getLngSjy()+""));
//        fyPlace.setLng(new BigDecimal(lnglat[1]));
//        fyPlace.setLat(new BigDecimal(lnglat[0]));
    	fyPlace.setLng(fyPlace.getLngSjy());
    	fyPlace.setLat(fyPlace.getLatSjy());
    	
    	int flag = fyPlaceService.updateFyPlace(fyPlace);
    	if(flag>0) {
        	return BaseResponse.generateOKResponseEntity("修改成功"); 
    	}
        return BaseResponse.generateBadResponseEntity("修改失败", null);
    }
    
    @PostMapping("/getApplyByPlaceId")
    @ApiOperation(value = "105、根据场景获取对应的审批记录", position = 105, notes = "")
    @ApiImplicitParams({
  	  @ApiImplicitParam(name = "placeId", value = "核酸采样点编号", required = true, example = "393"),
  	  @ApiImplicitParam(name = "pageNum", value = "当前页", required = false, example = "1"),
  	  @ApiImplicitParam(name = "pageSize", value = "分页大小", required = false, example = "15"),
  	  @ApiImplicitParam(name = "orderByColumn", value = "排序字段", required = false, example = "create_time"),
  	  @ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc", required = false, example = "asc"),
		 
	 })
    public ResponseEntity<BaseResponse<List<FyGoodsApply>>> getApplyByPlaceId(@RequestParam Long placeId
    		,@RequestParam(required = false,defaultValue = "1") Integer pageNum,@RequestParam(required = false,defaultValue = "20") Integer pageSize,@RequestParam(required = false,defaultValue = "create_time") String orderByColumn,@RequestParam(required = false,defaultValue = "desc") String isAsc)
    {
    	FyGoodsApply fyGoodsApply = new FyGoodsApply();
    	fyGoodsApply.setPlaceId(placeId);

        startPage();
        List<FyGoodsApply> list = applyService.selectFyGoodsApplyList(fyGoodsApply);
        list.forEach(n->{
        	FyGoods goods = new FyGoods();
        	goods.setApplyId(n.getApplyId());
        	n.setFyGoods(goodsService.selectFyGoodsList(goods));
        	n.setCreater(fyUserService.selectFyUserByUserId(Long.parseLong(n.getCreateBy())));
        });
        return BaseResponse.generateOKResponseEntity(getDataTable(list));
    }
    @ApiOperation(value = "106、根据审批节点查看申请详情", position = 106, notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(required=false,name="applyId",value="审批ID",example="1"),
    })
    @PostMapping({"/getApplyDetailByApplyId"})
    public ResponseEntity<BaseResponse<FyGoodsApply>> getApplyDetailByApplyId(@RequestParam Long applyId) throws Exception
    { 
        FyGoodsApply apply = applyService.selectFyGoodsApplyByApplyId(applyId);
        if(apply==null) {
        	return BaseResponse.generateBadResponseEntity("记录无效", null);
        }
        FyGoods goods = new FyGoods();
    	goods.setApplyId(applyId);
        apply.setFyGoods(goodsService.selectFyGoodsList(goods));
        apply.setCreater(fyUserService.selectFyUserByUserId(Long.parseLong(apply.getCreateBy())));
        
        FyGoodsApplyHis fyGoodsApplyHis = new FyGoodsApplyHis();
        fyGoodsApplyHis.setApplyId(apply.getApplyId());
        apply.setFyGoodsApplyHis(hisService.selectFyGoodsApplyHisList(fyGoodsApplyHis));
        return BaseResponse.generateOKResponseEntity(apply);
    }
    @ApiOperation(value = "107、获取小程序二维码", position = 107, notes = "适用于需要的码数量较少的业务场景。通过该接口生成的小程序码，永久有效，有数量限制")
    @ApiImplicitParams({
  	  @ApiImplicitParam(name = "placeId", value = "场所ID", required = true, example = "361"), 
  	  //@ApiImplicitParam(name = "path", value = "扫码进入的小程序页面路径，最大长度 128 字节，不能为空；对于小游戏，可以只传入 query 部分，来实现传参效果，如：传入 \"?foo=bar\"，即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:\"bar\"}", required = true, example = "15858558918"), 
    })
    @GetMapping(value = "/noToken/getwxacode",produces = MediaType.IMAGE_PNG_VALUE)
    public Object getwxacode2(@RequestParam Long placeId,@RequestParam(required = false,defaultValue = "pages/index/index") String path,HttpServletResponse response) {
  	  String accessToken = fyAccessTokenService.getAccessTokenNow()==null?"":fyAccessTokenService.getAccessTokenNow().getAccessToken();
  	  if(StringUtils.isBlank(accessToken)) {
  		  accessToken = WeChatUtils.getXcxAccessToken();
  		  FyAccessToken fyAccessToken = new FyAccessToken();
  		  fyAccessToken.setAccessToken(accessToken);
  		  fyAccessToken.setCreateTime(new Date());
  		  fyAccessTokenService.insertFyAccessToken(fyAccessToken);
  	  }
  	  return WeChatUtils.getwxacode2(placeId,accessToken,path).bodyBytes();
    }
    
    
    @ApiOperation(value = "201.按类型打卡情况统计，分为公安、卫健、社区 ", position = 201,notes = "")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
	})
	@RequestMapping(value = "/userSigninTypesta",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> userSigninTypesta() {
		try {
			String sql = "select * from v_user_signin_type_sta";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			return BaseResponse.generateOKResponseEntity(ListUtils.mapListSetKeyUncamelCase(list));
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
    
    @ApiOperation(value = "202.统计当前点位对应人数，当前点位打卡人数", position = 202,notes = "")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
        @ApiImplicitParam(required=false,name="placeId",value="场所ID",example="1"),
        @ApiImplicitParam(required=false,name="teamId",value="队伍ID",example="1"),
	})
	@RequestMapping(value = "/teamSigninSta",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> teamSigninSta(Long placeId,Long teamId) {
    	if(StringUtils.isNull(placeId)&&StringUtils.isNull(teamId)) {
    		return BaseResponse.generateBadResponseEntity("场所编号或者队伍编号至少传一个",null);
    	}
		try {
			Map<String,Object> map = fyUserSigninService.getSigninStaByPlaceOrTeamId(placeId, teamId);
			if(map == null) {
				return BaseResponse.generateBadResponseEntity("无签到信息",null);
			}
			//添加当前时段打卡人数
			List<FyUserSigninVo> signinUserList = fyUserSigninService.getSigninListByPlaceOrTeamId(placeId, teamId);
			map.put("currSigninList", signinUserList);
			return BaseResponse.generateOKResponseEntity(MapUtils.toCamelCaseMap(map));
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
    @ApiOperation(value = "203.当前在线人员", position = 203,notes = "")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
        @ApiImplicitParam(required=false,name="placeId",value="场所ID",example="393"),
        @ApiImplicitParam(required=false,name="teamId",value="队伍ID",example="393"),
	})
	@RequestMapping(value = "/teamSigninList",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<FyUserSigninVo>> teamSigninList(Long placeId,Long teamId) {
		try {
			//添加当前时段打卡人数
			List<FyUserSigninVo> signinUserList = fyUserSigninService.getSigninListByPlaceOrTeamId(placeId, teamId);
			return BaseResponse.generateOKResponseEntity(signinUserList);
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
    
    @ApiOperation(value = "204.导出当前当前队伍打卡人员清单", position = 204,notes = "")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
        @ApiImplicitParam(required=false,name="placeId",value="场所ID",example="1"),
        @ApiImplicitParam(required=false,name="teamId",value="队伍ID",example="1"),
	})
	@RequestMapping(value = "/exportTeamSigninList",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> exportTeamSigninList(Long placeId,Long teamId,HttpServletResponse response) {
    	if(StringUtils.isNull(placeId)&&StringUtils.isNull(teamId)) {
    		return BaseResponse.generateBadResponseEntity("场所编号或者队伍编号至少传一个",null);
    	}
    	List<FyUserSigninVo> signinUserList = fyUserSigninService.getSigninListByPlaceOrTeamId(placeId, teamId);
		ExcelUtil<FyUserSigninVo> util = new ExcelUtil<FyUserSigninVo>(FyUserSigninVo.class);
		util.exportExcel(response,signinUserList, "当前时段签到打卡数据", "当前时段签到打卡数据");
		return null;
	}
    
    @ApiOperation(value = "205.队伍清单，用来地图打点  经纬度套用核酸点的经纬度", position = 205,notes = "")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "teamName", value = "队伍名称", required = false, example = "海城"),
    	@ApiImplicitParam(name = "placeId", value = "场所编号", required = false, example = "200"),
    	@ApiImplicitParam(name = "mgrName", value = "指挥长", required = false, example = "林"),
    	@ApiImplicitParam(name = "mgrPhone", value = "手机号", required = false, example = "158"),
    	@ApiImplicitParam(name = "checkOrg", value = "检测机构", required = false, example = "158"),
    	@ApiImplicitParam(name = "pageNum", value = "当前页", required = false, example = "1"),
    	@ApiImplicitParam(name = "pageSize", value = "分页大小", required = false, example = "15"),
    	@ApiImplicitParam(name = "orderByColumn", value = "排序字段", required = false, example = "create_time"),
    	@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc", required = false, example = "asc"),
    })
    @PostMapping({"/teamList"})
    public ResponseEntity<BaseResponse<TableDataInfo<FyTeam>>> teamList(@ApiIgnore FyTeam fyTeam)
    {
        startPage();
        List<FyTeam> list = fyTeamService.selectFyTeamList(fyTeam);
        return BaseResponse.generateOKResponseEntity(getDataTable(list));
    }
    
    @ApiOperation(value = "401.需求派发情况统计 ", position = 401,notes = "分为 待受理、在办中、已受理、已接收 四种状态")
	@SuppressWarnings("unchecked")
	@ApiImplicitParams({
	})
	@RequestMapping(value = "/placeApplyStatusSta",method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<BaseResponse<Object>> placeApplyStatusSta() {
		try {
			String sql = "select * from v_place_apply_status_sta";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			return BaseResponse.generateOKResponseEntity(ListUtils.mapListSetKeyUncamelCase(list));
		}catch (Exception e) {
			return BaseResponse.generateBadResponseEntity("获取接口数据失败!", e.getMessage());
		}
	}
    
    @ApiOperation(value = "402.按状态获取需求清单 ", position = 402,notes = "分为 待受理、在办中、已受理、已接收 四种状态")
    @ApiImplicitParams({
        @ApiImplicitParam(required=false,name="applyStatus",value="当前审批节点 1待受理、2在办中、3已受理、4已接收",example="1"),
        @ApiImplicitParam(required=false,name="searchValue",value="搜索内容",example="1"),
    	@ApiImplicitParam(name = "pageNum", value = "当前页", required = false, example = "1"),
  	  	@ApiImplicitParam(name = "pageSize", value = "分页大小", required = false, example = "15"),
  	  	@ApiImplicitParam(name = "orderByColumn", value = "排序字段", required = false, example = "create_time"),
  	  	@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc", required = false, example = "desc"),
    })
    @PostMapping({"/applyListByStatus"})
    public ResponseEntity<BaseResponse<List<FyGoodsApply>>> applyListByStatus(String applyStatus,String searchValue
    		,@RequestParam(required = false,defaultValue = "1") Integer pageNum,@RequestParam(required = false,defaultValue = "20") Integer pageSize,@RequestParam(required = false,defaultValue = "create_time") String orderByColumn,@RequestParam(required = false,defaultValue = "desc") String isAsc) throws Exception
    { 
    	FyGoodsApply fyGoodsApply = new FyGoodsApply();
    	fyGoodsApply.setApplyStatus(applyStatus);
    	fyGoodsApply.setSearchValue(searchValue);

    	startPage();
        List<FyGoodsApply> list = applyService.selectFyGoodsApplyList(fyGoodsApply);
        list.forEach(n->{
        	FyGoods goods = new FyGoods();
        	goods.setApplyId(n.getApplyId());
        	n.setFyGoods(goodsService.selectFyGoodsList(goods));
        	n.setCreater(fyUserService.selectFyUserByUserId(Long.parseLong(n.getCreateBy())));
        });
        return BaseResponse.generateOKResponseEntity(getDataTable(list));
    }
    
    @ApiOperation(value = "501.获取实验室清单 ", position = 501,notes = "")
    @PostMapping("/labList")
    public ResponseEntity<BaseResponse<TableDataInfo<FyLab>>> list(FyLab fyLab)
    {
        startPage();
        List<FyLab> list = fyLabService.selectFyLabList(fyLab);
        return BaseResponse.generateOKResponseEntity(getDataTable(list));
    }
    //获取实验室详情
    @ApiOperation(value = "502.获取实验室详情 ", position = 502,notes = "")
    @PostMapping("/getLabById")
    @ApiImplicitParams({
        @ApiImplicitParam(required=true,name="labId",value="实验室编号",example="1"),
    })
    public ResponseEntity<BaseResponse<FyLab>> getLabById(@RequestParam Long labId)
    {
    	FyLab fyLab = fyLabService.selectFyLabByLabId(labId);
        return BaseResponse.generateOKResponseEntity(fyLab);
    }
    //更新实验室信息
    @Log(title = "实验室信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editLab")
    @ApiOperation(value = "503、编辑实验室信息", position = 503, notes = "")
    @ApiImplicitParams({
  	  @ApiImplicitParam(name = "labId", value = "实验室ID", required = true, example = "1"),
	  @ApiImplicitParam(name = "labName", value = "实验室名称", required = false, example = "1"),
	  @ApiImplicitParam(name = "lngSjy", value = "经度2000 格式", required = false, example = "1"),
	  @ApiImplicitParam(name = "latSjy", value = "纬度 2000格式", required = false, example = "1"),
		 
	 })
    public ResponseEntity<BaseResponse> editLab(@ApiIgnore FyLab fyLab)
    {
    	if(fyLab.getLabId()==null) {
        	return BaseResponse.generateBadResponseEntity("修改的时候labId不能为空", null);
    	}
    	SecuryUserDetail user = UserContext.getUserSession();
    	fyLab.setUpdateBy(user.getLoginName());
    	
    	//更新lngSjy latSjy 到 lng lat
//        double[] lnglat = GPSUtil.bd09_To_gps84(new Double(fyLab.getLatSjy()+""), new Double(fyLab.getLngSjy()+""));
//        fyLab.setLng(new BigDecimal(lnglat[1]));
//        fyLab.setLat(new BigDecimal(lnglat[0]));
    	fyLab.setLng(fyLab.getLngSjy());
    	fyLab.setLat(fyLab.getLatSjy());
    	
    	
    	int flag = fyLabService.updateFyLab(fyLab);
    	if(flag>0) {
        	return BaseResponse.generateOKResponseEntity("修改成功"); 
    	}
        return BaseResponse.generateBadResponseEntity("修改失败", null);
    }
}
